package processingExample;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import processing.core.PApplet;

@SuppressWarnings("serial")
public class ProcessingExample3 extends PApplet
{
	int x = 100;
	int y = 100;
	
	int x2 = 100;
	int y2 = 100;
	public void setup()
	{
		frameRate(40);
		size(200, 200);
		background(0xff, 0xff, 0);
	}
	
	public void draw()
	{
		background(0xff, 0xff, 0);
		ellipse(x, y, 25, 25);
		rect(x2, y2, 30, 30);
	}
	
	public void mousePressed(MouseEvent e)
	{
		System.out.println("position(x,y): " + e.getX() + "," + e.getY());
		x = e.getX();
		y = e.getY();
	}

	public void keyPressed (KeyEvent e)
	{
		char x = e.getKeyChar();
		if(x != KeyEvent.CHAR_UNDEFINED)
		{
			if(x == 'a')
			{
				System.out.println("You pressed a!");
			}
			else if(x == 'b')
			{
				System.out.println("You pressed b!");
			}
			else if(x == 'c')
			{
				System.out.println("You pressed c!");
			}
			else if(x == 'd')
			{
				System.out.println("You pressed d!");
			}
		}
		
		int key = e.getKeyCode();
		if (key != KeyEvent.VK_UNDEFINED)
		{
			if (key == KeyEvent.VK_UP)
			{
				y2 -= 10;
				System.out.println("Up Arrow pressed!");
			}
			if (key == KeyEvent.VK_DOWN)
			{
				y2 += 10;
				System.out.println("Down Arrow pressed!");
			}
			if (key == KeyEvent.VK_RIGHT)
			{
				x2 += 10;
				System.out.println("Right Arrow pressed!");
			}
			if (key == KeyEvent.VK_LEFT)
			{
				x2 -= 10;
				System.out.println("Left Arrow pressed!");
			}
			if (key == KeyEvent.VK_SPACE)
			{
				System.out.println("SpaceBar pressed!");
			}
		}
	}
}

